package ${package.Controller};
import ${package.Service}.${table.serviceName};
import ${package.Parent}.${cfg.dtoConvertPackage}.${entity}Convert;
import ${package.Entity}.${entity};
import ${package.Parent}.${cfg.dtoPackage}.${entity}AddDTO;
import ${package.Parent}.${cfg.dtoPackage}.${entity}UpdateDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzy.conf.JSONResult;
import java.util.List;
import javax.validation.constraints.NotBlank;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
* <p>
* ${table.comment!} 前端控制器
* </p>
*
* @author ${author}
* @since ${date}
*/
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
@Api(tags = "<#if table.comment??>${table.comment}</#if>")
<#if kotlin>
    class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>
    private ${table.serviceName} ${table.serviceName?uncap_first};
    private ${entity}Convert ${entity?uncap_first}Convert;
    @Autowired
    public ${table.controllerName}(${table.serviceName} ${table.serviceName?uncap_first},${entity}Convert ${entity?uncap_first}Convert) {
        this.${table.serviceName?uncap_first} = ${table.serviceName?uncap_first};
        this.${entity?uncap_first}Convert = ${entity?uncap_first}Convert;
    }

    @RequestMapping(value = "/getList", method = RequestMethod.POST)
    @ApiOperation("获取${table.comment!} 列表")
    public JSONResult getList(
    @ApiParam("每页显示行数") @RequestParam(name = "limit", required = true, defaultValue = "10") int limit,
    @ApiParam("当前页数") @RequestParam(name = "page", required = true, defaultValue = "1") int page
    ) {
        IPage<${entity}> page_obj = ${table.serviceName?uncap_first}.page(new Page<${entity}>(page, limit));
        return JSONResult.ok(page_obj);
    }


    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation("添加${table.comment!}")
    public JSONResult add(
        @ApiParam("${table.comment!}") @RequestBody @Validated ${entity}AddDTO data
    ) {
        ${entity} save_data = ${entity?uncap_first}Convert.addDtoToEntity(data);
        ${table.serviceName?uncap_first}.save(save_data);
        return JSONResult.ok();
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation("修改${table.comment!}")
    public JSONResult update(
        @ApiParam("${table.comment!}") @RequestBody @Validated ${entity}UpdateDTO data
    ) {
        ${entity} save_data = ${entity?uncap_first}Convert.updateDtoToEntity(data);
        ${table.serviceName?uncap_first}.updateById(save_data);
        return JSONResult.ok();
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation("删除${table.comment!}")
    public JSONResult delete(
        @ApiParam("ids") @RequestBody @Validated List<String> ids
    ) {
        ${table.serviceName?uncap_first}.removeByIds(ids);
        return JSONResult.ok();
    }

    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    @ApiOperation("获取${table.comment!}详情")
    public JSONResult get(
    @ApiParam("id") @PathVariable(value = "id") @NotBlank(message = "id不能为空") String id
    ) {
        return JSONResult.ok(${table.serviceName?uncap_first}.getById(id));
    }
}
</#if>
